<?php
echo $header;
echo $column_left;
echo $column_right;
$width_content = '100%';
if (($column_left) && ($column_right)) {
    $width_content = '48%';
} elseif (($column_left) || ($column_right)) {
    $width_content = '74%';
}
$style = '';
if ($column_left) {
    $style .= '; margin-left:1%';
}
if ($column_right) {
    $style .= '; margin-right:1%';
}
?>
<div class="content" style="width:<?php echo $width_content . $style; ?>"><?php echo $content_top; ?>
    <div class="breadcrumb">
        <?php foreach ($breadcrumbs as $breadcrumb) { ?>
            <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
        <?php } ?>
    </div>
    <ul data-role="listview" data-divider-theme="a" data-inset="true">
        <li data-role="list-divider"><h1><?php echo $heading_title; ?></h1></li>
    </ul>
    <form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="address">
        <div class="form" data-role="fieldcontain">
            <ul data-role="listview" data-divider-theme="a" data-inset="true">
                <li data-role="list-divider"><?php echo $text_edit_address; ?></li>
                <li>
                    <input placeholder="<?php echo $entry_firstname; ?>" type="text" name="firstname" value="<?php echo $firstname; ?>" /><span class="required">*</span>
                    <?php if ($error_firstname) { ?>
                        <div class="error"><?php echo $error_firstname; ?></div>
                    <?php } ?>
                </li>
                <li>
                    <input placeholder="<?php echo $entry_lastname; ?>" type="text" name="lastname" value="<?php echo $lastname; ?>" /><span class="required">*</span>
                    <?php if ($error_lastname) { ?>
                        <div class="error"><?php echo $error_lastname; ?></div>
                    <?php } ?>
                </li>
                <li>
                    <input placeholder="<?php echo $entry_company; ?>" type="text" name="company" value="<?php echo $company; ?>" />
                </li>
                <?php if ($company_id_display) { ?>
                    <li>
                        <input placeholder="<?php echo $entry_company_id; ?>" type="text" name="company_id" value="<?php echo $company_id; ?>" />
                        <?php if ($error_company_id) { ?>
                            <div class="error"><?php echo $error_company_id; ?></div>
                        <?php } ?>
                    </li>
                <?php } ?>
                <?php if ($tax_id_display) { ?>
                    <li>
                        <input placeholder="<?php echo $entry_tax_id; ?>" type="text" name="tax_id" value="<?php echo $tax_id; ?>" />
                        <?php if ($error_tax_id) { ?>
                            <div class="error"><?php echo $error_tax_id; ?></div>
                        <?php } ?>
                    </li>
                <?php } ?>
                <li>
                    <input placeholder="<?php echo $entry_address_1; ?>" type="text" name="address_1" value="<?php echo $address_1; ?>" /><span class="required">*</span>
                    <?php if ($error_address_1) { ?>
                        <div class="error"><?php echo $error_address_1; ?></div>
                    <?php } ?>
                </li>
                <li>
                    <input placeholder="<?php echo $entry_address_2; ?>" type="text" name="address_2" value="<?php echo $address_2; ?>" />
                </li>
                <li>
                    <input placeholder="<?php echo $entry_city; ?>" type="text" name="city" value="<?php echo $city; ?>" /><span class="required">*</span>
                    <?php if ($error_city) { ?>
                        <div class="error"><?php echo $error_city; ?></div>
                    <?php } ?>
                </li>
                <li>
                    <input placeholder="<?php echo $entry_postcode; ?>" type="text" name="postcode" value="<?php echo $postcode; ?>" /><span id="postcode-required" class="required">*</span>
                    <?php if ($error_postcode) { ?>
                        <div class="error"><?php echo $error_postcode; ?></div>
                    <?php } ?>
                </li>
                <li>
                    <label for="country_id"><span class="required">*</span> <?php echo $entry_country; ?></label>
                    <select name="country_id" id="country_id">
                        <option value=""><?php echo $text_select; ?></option>
                        <?php foreach ($countries as $country) { ?>
                            <option value="<?php echo $country['country_id']; ?>"<?php echo ($country['country_id'] == $country_id ? ' selected="selected"' : ''); ?>><?php echo $country['name']; ?></option>
                        <?php } ?>
                    </select>
                    <?php if ($error_country) { ?>
                        <div class="error"><?php echo $error_country; ?></div>
                    <?php } ?>
                </li>
                <li>
                    <label for="zone_id"><span class="required">*</span> <?php echo $entry_zone; ?></label>
                    <select name="zone_id" id="zone_id">
                    </select>
                    <?php if ($error_zone) { ?>
                        <div class="error"><?php echo $error_zone; ?></div>
                    <?php } ?>
                </li>
                <li>
                    <fieldset data-role="controlgroup" data-type="horizontal">
                        <legend><?php echo $entry_default; ?></legend>
                        <?php if ($default) { ?>
                            <input type="radio" name="default" id="radio-default-1" value="1" checked="checked" />
                            <label for="radio-default-1"><?php echo $text_yes; ?></label>
                            <input type="radio" name="default" id="radio-default-0" value="0" />
                            <label for="radio-default-0"><?php echo $text_no; ?></label>
                        <?php } else { ?>
                            <input type="radio" name="default" id="radio-default-1" value="1"/>
                            <label for="radio-default-1"><?php echo $text_yes; ?></label>
                            <input type="radio" name="default" id="radio-default-0" value="0" checked="checked" />
                            <label for="radio-default-0"><?php echo $text_no; ?></label>
                        <?php } ?>
                    </fieldset>
                </li>
            </ul>
            <div class="ui-body buttons">
                <fieldset class="ui-grid-a">
                    <div class="ui-block-a left"><a data-icon="arrow-l" href="<?php echo $back; ?>" data-role="button" class="button"><span><?php echo $button_back; ?></span></a></div>
                    <div class="ui-block-b right"><a data-icon="check" data-theme="c" onclick="$('#address').submit();" data-role="button" class="button"><span><?php echo $button_continue; ?></span></a></div>
                </fieldset>
            </div>
        </div>
    </form>
    <?php echo $content_bottom; ?></div>
<script type="text/javascript"><!--
    $('select[name=\'country_id\']').bind('change', function() {
        $.ajax({
            url: 'index.php?route=account/address/country&country_id=' + this.value,
            dataType: 'json',
            beforeSend: function() {
                $('select[name=\'country_id\']').after('<span class="wait">&nbsp;<img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
            },
            complete: function() {
                $('.wait').remove();
            },
            success: function(json) {
                if (json['postcode_required'] == '1') {
                    $('#postcode-required').show();
                } else {
                    $('#postcode-required').hide();
                }

                html = '<option value=""><?php echo $text_select; ?></option>';

                if (json['zone'] != '') {
                    for (i = 0; i < json['zone'].length; i++) {
                        html += '<option value="' + json['zone'][i]['zone_id'] + '"';

                        if (json['zone'][i]['zone_id'] == '<?php echo $zone_id; ?>') {
                            html += ' selected="selected"';
                        }

                        html += '>' + json['zone'][i]['name'] + '</option>';
                    }
                } else {
                    html += '<option value="0" selected="selected"><?php echo $text_none; ?></option>';
                }

                $('select[name=\'zone_id\']').html(html);
            },
            error: function(xhr, ajaxOptions, thrownError) {
                alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
            }
        });
    });

    $('select[name=\'country_id\']').trigger('change');
    //--></script>
<?php echo $footer; ?>